package com.example.controller;

import com.example.common.Result;
import com.example.entity.Employee;
import com.example.entity.Organization;
import com.example.service.EmployeeService;
import com.example.service.OrganizationService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/organization")
public class OrganizationController {

    @Resource
    private OrganizationService organizationService;

    @GetMapping("/selectAll")
    public Result selectAll(Organization organization){
        List<Organization> list = organizationService.selectAll(organization);
        return Result.success(list);
    }

    //分页查询
    @GetMapping("/selectPage")
    public Result selectPage(Organization organization,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Organization> pageInfo = organizationService.selectPage(organization,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping("/insert")
    public Result add(@RequestBody Organization organization){
        organizationService.add(organization);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Organization organization){
        organizationService.update(organization);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        organizationService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer>ids){
        organizationService.deleteBatch(ids);
        return Result.success();
    }

}
